package com.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONArray;
import com.util.ConfigUtil;

import com.util.BODY;
import com.util.DateUtil;
import com.util.HttpRequest;
import com.util.JSONUtil;
import com.util.OpenKey;
import com.util.ReadConfig;
import com.util.SessionInfo;

/**
 * 缴存历史记录
 * @author 
 */
@Controller
@RequestMapping("/bjgncontroller")
public class bjgnController {

	private static final Logger logger = Logger.getLogger(bjgnController.class);
	Map map  = new HashMap();
	List list = new ArrayList();
	  
	@RequestMapping("/test")
	@ResponseBody
	public String entryinterface(HttpServletRequest request,HttpSession session, HttpServletResponse response ,String limit ,String id,String start,String end,String RQ,String SJ) throws IOException{
		//读取配置文件路劲
		SessionInfo sessionIn = (SessionInfo) session.getAttribute(ConfigUtil.getSessionInfoName());
		String interfaceUrl = ReadConfig.readValue();
		int a=0;
		int b=0;
		Calendar cal = Calendar.getInstance();
		int year = cal.get(Calendar.YEAR);
		int month = cal.get(Calendar.MONTH )+1;
		if(RQ!="" && RQ!=null){
			RQ=RQ.replace("-", "");
			String RQ1=RQ.substring(0, 6);
			a=Integer.parseInt(RQ1);
			}
		else{
			a=Integer.parseInt(year+"01");
		}
		
		
		Map reqMap = new HashMap();
		BODY by=new BODY();
		OpenKey opk=new OpenKey();
		//接口编码
		reqMap.put("AUTHORITY", "YBGJJ195");
		//接口参数
		reqMap.put("OpenKey",sessionIn.getKEY());
		by.setDWZH(sessionIn.getDWZH());
		by.setNIANYUE(a+"");
		by.setDQDM(sessionIn.getDQM());
		reqMap.put("BODY",by);
		List retlist=new ArrayList();
		String  result = opk.getOpenKey(reqMap, session);
		Map retMap = JSONUtil.toMap(result);
		if(retMap.get("RETURNCODE").equals("100")){
		retMap = (Map) retMap.get("body");
    	 retlist = (List)retMap.get("RETDATA");
		}
			Map resMap = JSONUtil.toMap(result);
					List listttmp = new ArrayList();
						map.put("code", 0); 
						map.put("msg", resMap.get("RETURNDESC"));
						map.put("data",retlist);
						list.add(resMap);
						response.setHeader("Content-type", "text/html;charset=UTF-8");
						response.setCharacterEncoding("UTF-8");
						String jsonString = JSONUtil.ToJsongString2(map);
						PrintWriter pw = response.getWriter();
						pw.write(jsonString);
					

		return null;
	}
	@RequestMapping("/test1")
	@ResponseBody
	public String entryinterface1(HttpServletRequest request,HttpSession session, HttpServletResponse response , String limit ,String id,String start,String end ,
		String XINGMING,String GRZH,String ZJHM,String BZ,String BJNY,String BJJE	) throws IOException, ParseException{
		//读取配置文件路劲
		SessionInfo sessionIn = (SessionInfo) session.getAttribute(ConfigUtil.getSessionInfoName());
		String interfaceUrl = ReadConfig.readValue();
		Map reqMap = new HashMap();
		//接口编码
		BJNY=BJNY.replace("-", "").trim();
		reqMap.put("AUTHORITY", "YBGJJ196");
		//接口参数
		
		JSONArray jsonArray = new JSONArray();
		String result="";
			BODY body=new BODY();
			body.setJCYH(sessionIn.getJCYH());
			body.setDQDM(sessionIn.getDQM());
			body.setDWZH(sessionIn.getDWZH());
			body.setNIANYUE(BJNY);
			body.setFRDB("网厅");
			body.setGSDQDM("");
			body.setZJHM(ZJHM);
			body.setXINGMING(XINGMING);
			body.setGRZH(GRZH);
			body.setBJJE(BJJE);
			if(BZ!=null)
				body.setBZ(BZ);
			else
				body.setBZ("");
			body.setDWZH(sessionIn.getDWZH());
			reqMap.put("BODY",body);
			reqMap.put("OpenKey",sessionIn.getKEY());
			//请求
			OpenKey opk=new OpenKey();
			 result=opk.getOpenKey(reqMap, session);
		
	
		Map retMap = JSONUtil.toMap(result);
		retMap = (Map) retMap.get("body");
    	List retlist = (List)retMap.get("RETDATA");
		if(result != null){
			Map resMap = JSONUtil.toMap(result);
				map.put("code", 0); 
				map.put("msg", resMap.get("RETURNDESC"));;
				map.put("data",retlist);
				list.add(resMap);
				response.setHeader("Content-type", "text/html;charset=UTF-8");
				response.setCharacterEncoding("UTF-8");
				String jsonString = JSONUtil.ToJsongString2(map);
				PrintWriter pw = response.getWriter();
				pw.write(jsonString);
		}
		return null;
	}
	
	@RequestMapping("/test2")
	@ResponseBody
	public String entryinterface2(HttpServletRequest request,HttpSession session, HttpServletResponse response , String limit ,String ID,String start,String end,String NY,String XINGMING) throws IOException, ParseException{
		//读取配置文件路劲
		SessionInfo sessionIn = (SessionInfo) session.getAttribute(ConfigUtil.getSessionInfoName());
		String interfaceUrl = ReadConfig.readValue();
		Map reqMap = new HashMap();
		//接口编码
		reqMap.put("AUTHORITY", "YBGJJ197");
		//接口参数
	
		BODY body=new BODY();
		if(XINGMING!=null&&!XINGMING.equals(""))
			body.setXINGMING(XINGMING);
		body.setDWZH(sessionIn.getDWZH());
		reqMap.put("BODY",body);
		reqMap.put("OpenKey",sessionIn.getKEY());
		OpenKey opk=new OpenKey();
		String result=opk.getOpenKey(reqMap, session);
		Map retMap = JSONUtil.toMap(result);
		retMap = (Map) retMap.get("body");
    	List retlist = (List)retMap.get("RETDATA");
		if(result != null){
			Map resMap = JSONUtil.toMap(result);
				map.put("code", 0); 
				map.put("msg", resMap.get("RETURNDESC"));;
				map.put("data",retlist);
				list.add(resMap);
				response.setHeader("Content-type", "text/html;charset=UTF-8");
				response.setCharacterEncoding("UTF-8");
				String jsonString = JSONUtil.ToJsongString2(map);
				PrintWriter pw = response.getWriter();
				pw.write(jsonString);
		}
		return null;
	}
	
	@RequestMapping("/test3")
	@ResponseBody
	public String entryinterface3(HttpServletRequest request,HttpSession session, HttpServletResponse response , String limit ,String ID,String start,String end,String NY) throws IOException, ParseException{
		//读取配置文件路劲
		SessionInfo sessionIn = (SessionInfo) session.getAttribute(ConfigUtil.getSessionInfoName());
		String interfaceUrl = ReadConfig.readValue();
		Map reqMap = new HashMap();
		//接口编码
		reqMap.put("AUTHORITY", "YBGJJ198");
		//接口参数
		BODY body=new BODY();
		body.setDWZH(sessionIn.getDWZH());
		reqMap.put("BODY",body);
		reqMap.put("OpenKey",sessionIn.getKEY());
		OpenKey opk=new OpenKey();
		String result=opk.getOpenKey(reqMap, session);
		Map retMap = JSONUtil.toMap(result);
		retMap = (Map) retMap.get("body");
    	List retlist = (List)retMap.get("RETDATA");
		if(result != null){
			Map resMap = JSONUtil.toMap(result);
				map.put("code", 0); 
				map.put("msg", resMap.get("RETURNDESC"));;
				map.put("data",retlist);
				list.add(resMap);
				response.setHeader("Content-type", "text/html;charset=UTF-8");
				response.setCharacterEncoding("UTF-8");
				String jsonString = JSONUtil.ToJsongString2(map);
				PrintWriter pw = response.getWriter();
				pw.write(jsonString);
		}
		return null;
	}
	
	@RequestMapping("/test4")
	@ResponseBody
	public String entryinterface4(HttpServletRequest request,HttpSession session, HttpServletResponse response , String limit ,String ID,String start,String end,String NY) throws IOException, ParseException{
		//读取配置文件路劲
		SessionInfo sessionIn = (SessionInfo) session.getAttribute(ConfigUtil.getSessionInfoName());
		String interfaceUrl = ReadConfig.readValue();
		Map reqMap = new HashMap();
		//接口编码
		reqMap.put("AUTHORITY", "YBGJJ199");
		//接口参数
		BODY body=new BODY();
		body.setNIANYUE(NY);
		body.setDWZH(sessionIn.getDWZH());
		reqMap.put("BODY",body);
		reqMap.put("OpenKey",sessionIn.getKEY());
		OpenKey opk=new OpenKey();
		String result=opk.getOpenKey(reqMap, session);
		Map retMap = JSONUtil.toMap(result);
		retMap = (Map) retMap.get("body");
    	List retlist = (List)retMap.get("RETDATA");
		if(result != null){
			Map resMap = JSONUtil.toMap(result);
				map.put("code", 0); 
				map.put("msg", resMap.get("RETURNDESC"));;
				map.put("data",retlist);
				list.add(resMap);
				response.setHeader("Content-type", "text/html;charset=UTF-8");
				response.setCharacterEncoding("UTF-8");
				String jsonString = JSONUtil.ToJsongString2(map);
				PrintWriter pw = response.getWriter();
				pw.write(jsonString);
		}
		return null;
	}
	
	@RequestMapping("/test5")
	@ResponseBody
	public String entryinterface5(HttpServletRequest request,HttpSession session, HttpServletResponse response , String limit ,String ID,String start,String end,String NY) throws IOException, ParseException{
		//读取配置文件路劲
		SessionInfo sessionIn = (SessionInfo) session.getAttribute(ConfigUtil.getSessionInfoName());
		String interfaceUrl = ReadConfig.readValue();
		Map reqMap = new HashMap();
		//接口编码
		reqMap.put("AUTHORITY", "YBGJJ200");
		//接口参数
		BODY body=new BODY();
		body.setDWZH(sessionIn.getDWZH());
		reqMap.put("BODY",body);
		reqMap.put("OpenKey",sessionIn.getKEY());
		OpenKey opk=new OpenKey();
		String result=opk.getOpenKey(reqMap, session);
		Map retMap = JSONUtil.toMap(result);
		retMap = (Map) retMap.get("body");
    	List retlist = (List)retMap.get("RETDATA");
		if(result != null){
			Map resMap = JSONUtil.toMap(result);
				map.put("code", 0); 
				map.put("msg", resMap.get("RETURNDESC"));;
				map.put("data",retlist);
				list.add(resMap);
				response.setHeader("Content-type", "text/html;charset=UTF-8");
				response.setCharacterEncoding("UTF-8");
				String jsonString = JSONUtil.ToJsongString2(map);
				PrintWriter pw = response.getWriter();
				pw.write(jsonString);
		}
		return null;
	}
	@RequestMapping("/test6")
	@ResponseBody
	public String entryinterface6(HttpSession session,HttpServletRequest request, HttpServletResponse response ,String limit ,String YJJE,String NY) throws IOException{
		
		SessionInfo sessionIn = (SessionInfo) session.getAttribute(ConfigUtil.getSessionInfoName());
		//读取配置文件路劲
		String interfaceUrl = ReadConfig.readValue();
		Map reqMap = new HashMap();
		BODY b=new BODY();
		
		String[] s = NY.split(","); 
		String[] j = YJJE.split(",");  
		Map retMap=new HashMap();
		for(int i=0;i<s.length;i++){
			b.setDWZH(sessionIn.getDWZH());
			b.setNIANYUE(s[i]);
			b.setYJCE(j[i]);
			OpenKey ope=new OpenKey();
			//接口编码
			reqMap.put("AUTHORITY", "YBGJJ201");
			//接口参数
			reqMap.put("OpenKey",sessionIn.getKEY());
			b.setDWZH(sessionIn.getDWZH());
			reqMap.put("BODY",b);
			String resu=ope.getOpenKey(reqMap, session);
			retMap = JSONUtil.toMap(resu);
			if(!retMap.get("RETURNCODE").toString().equals("100"))
				break;
			else
				continue;
		}
	
		
		
		
		 Map retMap1 = (Map) retMap.get("body");
		if(retMap1 != null){
				map.put("code", 0); 
				map.put("msg", retMap.get("RETURNDESC"));
				map.put("data", retMap1.get("RETDATA"));
				response.setHeader("Content-type", "text/html;charset=UTF-8");
				response.setCharacterEncoding("UTF-8");
				String jsonString = JSONUtil.ToJsongString2(map);
				PrintWriter pw = response.getWriter();
				pw.write(jsonString);
		}
		 
		return null;
	}
	
	@RequestMapping("/test7")
	@ResponseBody
	public String entryinterface7(HttpServletRequest request,HttpSession session, HttpServletResponse response , String limit ,String id,String start,String end) throws IOException, ParseException{
		//读取配置文件路劲
		SessionInfo sessionIn = (SessionInfo) session.getAttribute(ConfigUtil.getSessionInfoName());
		String interfaceUrl = ReadConfig.readValue();
		Map reqMap = new HashMap();
		OpenKey opk=new OpenKey();
		//接口编码
		reqMap.put("AUTHORITY", "YBGJJ219");
		//接口参数
		BODY body=new BODY();
		body.setDWZH(sessionIn.getDWZH());
		reqMap.put("BODY",body);
		reqMap.put("OpenKey",sessionIn.getKEY());
		String  result = opk.getOpenKey(reqMap, session);
		Map retMap = JSONUtil.toMap(result);
		retMap = (Map) retMap.get("body");
    	List retlist = (List)retMap.get("RETDATA");
		if(result != null){
			Map resMap = JSONUtil.toMap(result);
				map.put("code", 0); 
				map.put("msg", resMap.get("RETURNDESC"));;
				map.put("data",retlist);
				list.add(resMap);
				response.setHeader("Content-type", "text/html;charset=UTF-8");
				response.setCharacterEncoding("UTF-8");
				String jsonString = JSONUtil.ToJsongString2(map);
				PrintWriter pw = response.getWriter();
				pw.write(jsonString);
		}
		return null;
	}
	@RequestMapping("/test8")
	@ResponseBody
	public String entryinterface8(HttpServletRequest request,HttpSession session, HttpServletResponse response , String limit ,String id,String start,String end) throws IOException, ParseException{
		//读取配置文件路劲
		SessionInfo sessionIn = (SessionInfo) session.getAttribute(ConfigUtil.getSessionInfoName());
		String interfaceUrl = ReadConfig.readValue();
		Map reqMap = new HashMap();
		OpenKey opk=new OpenKey();
		//接口编码
		reqMap.put("AUTHORITY", "YBGJJ202");
		//接口参数
		BODY body=new BODY();
		body.setDWZH(sessionIn.getDWZH());
		reqMap.put("BODY",body);
		reqMap.put("OpenKey",sessionIn.getKEY());
		String  result = opk.getOpenKey(reqMap, session);
		Map retMap = JSONUtil.toMap(result);
		retMap = (Map) retMap.get("body");
    	List retlist = (List)retMap.get("RETDATA");
		if(result != null){
			Map resMap = JSONUtil.toMap(result);
				map.put("code", 0); 
				map.put("msg", resMap.get("RETURNDESC"));;
				map.put("data",retlist);
				list.add(resMap);
				response.setHeader("Content-type", "text/html;charset=UTF-8");
				response.setCharacterEncoding("UTF-8");
				String jsonString = JSONUtil.ToJsongString2(map);
				PrintWriter pw = response.getWriter();
				pw.write(jsonString);
		}
		return null;
	}
	
	@RequestMapping("/bjts")
	@ResponseBody
	public String bjts(HttpSession session,HttpServletRequest request, HttpServletResponse response ,String limit ,String YJJE,String NY) throws IOException{
		

		SessionInfo sessionIn = (SessionInfo) session.getAttribute(ConfigUtil.getSessionInfoName());
		//读取配置文件路劲
		String interfaceUrl = ReadConfig.readValue();
		Map reqMap = new HashMap();
		BODY b=new BODY();
		Map retMap=new HashMap();
		String[] l=NY.split(",");
		for(int i=0;i<l.length;i++){
			OpenKey ope=new OpenKey();
			//接口编码
			reqMap.put("AUTHORITY", "YBGJJ203");
			//接口参数
			reqMap.put("OpenKey",sessionIn.getKEY());
			b.setDWZH(sessionIn.getDWZH());
			b.setXINGMING(sessionIn.getXINGMING());
			b.setNIANYUE(l[i]);
			reqMap.put("BODY",b);
			
			String resu=ope.getOpenKey(reqMap, session);
			retMap = JSONUtil.toMap(resu);
		}
	
		
		
		
		 Map retMap1 = (Map) retMap.get("body");
		if(retMap1 != null){
				map.put("code", 0); 
				map.put("msg", retMap.get("RETURNDESC"));
				map.put("data", retMap1.get("RETDATA"));
				response.setHeader("Content-type", "text/html;charset=UTF-8");
				response.setCharacterEncoding("UTF-8");
				String jsonString = JSONUtil.ToJsongString2(map);
				PrintWriter pw = response.getWriter();
				pw.write(jsonString);
		}
		 
		return null;
	}
	
	@RequestMapping("/lr")
	@ResponseBody
	public String lr(HttpSession session,HttpServletRequest request, HttpServletResponse response ,String limit ,String YJJE,String NY,String ZJHM,String XINGMING) throws IOException{
		

		SessionInfo sessionIn = (SessionInfo) session.getAttribute(ConfigUtil.getSessionInfoName());
		//读取配置文件路劲
		String interfaceUrl = ReadConfig.readValue();
		Map reqMap = new HashMap();
		BODY b=new BODY();
		Map retMap=new HashMap();
			OpenKey ope=new OpenKey();
			//接口编码
			reqMap.put("AUTHORITY", "YBGJJ204");
			//接口参数
			reqMap.put("OpenKey",sessionIn.getKEY());
			if(ZJHM==null)
				b.setZJHM("");
			else
				b.setZJHM(ZJHM);
			if(XINGMING==null)
				b.setXINGMING("");
			else
				b.setXINGMING(XINGMING);
			b.setDWZH(sessionIn.getDWZH());
			reqMap.put("BODY",b);
			
			String resu=ope.getOpenKey(reqMap, session);
			retMap = JSONUtil.toMap(resu);
	
		
		
		
		 Map retMap1 = (Map) retMap.get("body");
		if(retMap1 != null){
				map.put("code", 0); 
				map.put("msg", retMap.get("RETURNDESC"));
				map.put("data", retMap1.get("RETDATA"));
				response.setHeader("Content-type", "text/html;charset=UTF-8");
				response.setCharacterEncoding("UTF-8");
				String jsonString = JSONUtil.ToJsongString2(map);
				PrintWriter pw = response.getWriter();
				pw.write(jsonString);
		}
		 
		return null;
	}
}
